import type { FormSchema } from '@/components/core/schema-form/';


const isRoot = (type: API.CategaryListResultItem['parentId']) => type === '0';


export const categarySchemas: FormSchema<API.CategaryAddParams>[] = [
  {
    field: 'parentId',
    component: 'TreeSelect',
    label: '所属类别',
    componentProps: {
      fieldNames: {
        label: 'name',
        value: 'id',
      },
      colProps: {
        span: 12,
      },
      getPopupContainer: () => document.body,
    },
    rules: [{ required: true, type: 'string' }],
  },
  {
    field: 'name',
    component: 'Input',
    label: '节点名称',
    rules: [{ required: true, type: 'string' }],
    colProps: {
      span: 12,
    },
  },
  {
    field: 'code',
    component: 'Input',
    label: '节点编码',
    rules: [{ required: true, type: 'string' }],
    vIf: ({ formModel }) => !isRoot(formModel['parentId']),
    colProps: {
      span: 12,
    },
  },
  {
    field: 'categaryCode',
    component: 'Input',
    label: '类别代码',
    rules: [{ required: true, type: 'string' }],
    vIf: ({ formModel }) => isRoot(formModel['parentId']),
    colProps: {
      span: 12,
    },

  },
  {
    field: 'sysCode',
    component: 'Input',
    label: '系统编码',
    vIf: ({ formModel }) => isRoot(formModel['parentId']),
    colProps: {
      span: 12,
    },
  },
  {
    field: 'lableName',
    component: 'Input',
    label: 'lable信息',
    rules: [{ required: true, type: 'string' }],
    vIf: ({ formModel }) => isRoot(formModel['parentId']),
    colProps: {
      span: 12,
    },
  },
  
  {
    field: 'visible',
    component: 'Switch',
    label: '是否启用',
    rules: [{ required: true, type: 'string' }],
    defaultValue: '0',
    colProps: {
      span: 12,
    },
    componentProps: {
      checkedValue: '0',
      unCheckedValue: '1',
    },
  },

  {
    field: 'orderNum',
    component: 'InputNumber',
    label: '排序号',
    colProps: {
      span: 12,
    },
    componentProps: {
      style: {
        width: '100%',
      },
    },
  },
];
